//创建之前先把Home.vue和Welcome.vue中用到的Antd组件按需引入一下,顺带着把router.js引入一下,
//修改后的main.js
import Vue from "vue";
import Router from "vue-router";
import routes from "./router";
import App from "./App.vue";
import storejs from "store";
import moment from "moment";
import { Button as ElButton, Input as ELInput, Tree as ElTree,Loading  } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Updater from "./utils/AutoUpdate.js"

//按需引入Antd组件库
import {
  Button,
  Form,
  FormModel,
  Input,
  Icon,
  Checkbox,
  message,
  Layout,
  Menu,
  Skeleton,
  Table,
  Pagination,
  ConfigProvider,
  Modal,
  InputNumber,
  Select,
  Upload,
  PageHeader,
  Radio,
  Descriptions,
  List,
  Empty,
  Spin,
  Divider,
  Avatar,
  Popover,
  Dropdown,
  Card,
  Tree,
  Slider,
  Row,
  Col,
  Tabs,
  Tooltip,
  Carousel
} from "ant-design-vue";
//引入Antd组件库CSS文件
import "ant-design-vue/dist/antd.css";
Vue.use(Button);
Vue.use(Form);
Vue.use(FormModel);
Vue.use(Input);
Vue.use(Icon);
Vue.use(Checkbox);
Vue.use(Layout);
Vue.use(Menu);
Vue.use(Skeleton);
Vue.use(Table);
Vue.use(Pagination);
Vue.use(Modal);
Vue.use(InputNumber);
Vue.use(Select);
Vue.use(Upload);
Vue.use(PageHeader);
Vue.use(Radio);
Vue.use(Descriptions);
Vue.use(List);
Vue.use(Empty);
Vue.use(Spin);
Vue.use(Divider);
Vue.use(Avatar);
Vue.use(Popover);
Vue.use(Dropdown);
Vue.use(Card);
Vue.use(Tree);
Vue.use(Slider);
Vue.use(Row);
Vue.use(Col);
Vue.use(Tabs);
Vue.use(Tooltip);
Vue.use(Carousel);
Vue.use(ElButton)
Vue.use(ELInput)
Vue.use(ElTree)
Vue.use(Loading.directive);
Vue.component(ConfigProvider.name, ConfigProvider);

//message 是全局提示它的触发是方法调用的，所以直接绑定在Vue的原型上
//这样无论何时用Vue.message都可以弹出全局提示
Vue.prototype.$message = message;
Vue.prototype.$confirm = Modal.confirm;

Vue.config.productionTip = false;
Vue.prototype.$storejs = storejs;
Vue.prototype.$moment = moment;

Vue.config.devtools = true;

Vue.use(Router);
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  const a = originalPush.call(this, location);
  if (a) return a.catch((err) => err);
};
const router = new Router(routes);
router.beforeEach((to, from, next) => {
  if (to.path === "/index" || to.path === "/home") {
    next();
  } else {
    if (storejs.get("token")) {
      next();
    } else {
      next({ path: "/index" });
    }
  }
});
//引入store
import store from "./store";

//前端重新部署通知用户刷新网页
const AutoUpdate = new Updater()
AutoUpdate.on('update',()=>{
  setTimeout(async()=>{
      const result = confirm('当前网站有更新，请点击确定刷新页面');
      if(result){
        location.reload();
      }
  }, 2000)
})


new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
